package com.ruoyi.tea.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.uuid.UUID;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tea.domain.TeaRecoring;
import com.ruoyi.tea.service.ITeaRecoringService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 录播记录Controller
 *
 * @author ruoyi
 * @date 2022-07-31
 */
@Controller
@RequestMapping("/tea/recoring")
public class TeaRecoringController extends BaseController {
    private String prefix = "tea/recoring";

    @Autowired
    private ITeaRecoringService teaRecoringService;

    @RequiresPermissions("tea:recoring:view")
    @GetMapping()
    public String recoring() {
        return prefix + "/recoring";
    }

    /**
     * 查询录播记录列表
     */
    @RequiresPermissions("tea:recoring:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TeaRecoring teaRecoring) {
        startPage();
        List<TeaRecoring> list = teaRecoringService.selectTeaRecoringList(teaRecoring);
        return getDataTable(list);
    }

    /**
     * 导出录播记录列表
     */
    @RequiresPermissions("tea:recoring:export")
    @Log(title = "录播记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeaRecoring teaRecoring) {
        List<TeaRecoring> list = teaRecoringService.selectTeaRecoringList(teaRecoring);
        ExcelUtil<TeaRecoring> util = new ExcelUtil<TeaRecoring>(TeaRecoring.class);
        return util.exportExcel(list, "录播记录数据");
    }

    /**
     * 新增录播记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存录播记录
     */
    @RequiresPermissions("tea:recoring:add")
    @Log(title = "录播记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TeaRecoring teaRecoring) {
        SysUser sysUser = getSysUser();
        teaRecoring.setMediaCode(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "-" + sysUser.getUserId());
        return toAjax(teaRecoringService.insertTeaRecoring(teaRecoring));
    }

    /**
     * 修改录播记录
     */
    @RequiresPermissions("tea:recoring:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TeaRecoring teaRecoring = teaRecoringService.selectTeaRecoringById(id);
        mmap.put("teaRecoring", teaRecoring);
        return prefix + "/edit";
    }

    /**
     * 修改保存录播记录
     */
    @RequiresPermissions("tea:recoring:edit")
    @Log(title = "录播记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TeaRecoring teaRecoring) {
        return toAjax(teaRecoringService.updateTeaRecoring(teaRecoring));
    }

    /**
     * 删除录播记录
     */
    @RequiresPermissions("tea:recoring:remove")
    @Log(title = "录播记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(teaRecoringService.deleteTeaRecoringByIds(ids));
    }
}
